﻿<%@ WebHandler Language="C#" Class="ZSKaoHeLookBoardHanlder" %>

using System;
using System.Web;
using Newtonsoft.Json;
using Newtonsoft.Json.Converters;
using System.Collections.Generic;
using System.Linq;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
using System.Text;
using System.Web.SessionState;
using System.IO;
using ReportBusiness;
public class ZSKaoHeLookBoardHanlder : IHttpHandler
{
    public bool IsReusable { get { return false; } }
    private static ZSKaoHeLookBoardBusiness pdb = new ZSKaoHeLookBoardBusiness();
    public void ProcessRequest(HttpContext context)
    {
        //本月任务机型分布(饼图)
        if (context.Request.QueryString["type"] != null && context.Request.QueryString["type"] == "GetProdutfamily")
        {
            DataTable dt = pdb.GetProdutfamily();
            var json = JsonConvert.SerializeObject(dt);
            context.Response.ContentType = "text/json";
            context.Response.Write(json.ToString());
            context.Response.End();
        }
        //各工区剩余任务(文字)
        if (context.Request.QueryString["type"] != null && context.Request.QueryString["type"] == "GetWorkcenterNotFinishedInfo")
        {
            Dictionary<string, object> para = new Dictionary<string, object>();
            if (context.Request.QueryString["factoryid"] != null)
            {
                para["factoryid"] = EncryptAndDecryptTool.DesDecrypt(context.Request.QueryString["factoryid"]);
            }
            DataTable dt = pdb.GetWorkcenterNotFinishedInfo(para);
            var json = JsonConvert.SerializeObject(dt);
            context.Response.ContentType = "text/json";
            context.Response.Write(json.ToString());
            context.Response.End();
        }
        //各中心任务完成情况（柱状图）
        if (context.Request.QueryString["type"] != null && context.Request.QueryString["type"] == "GetWorkcenterBarInfo")
        {
            Dictionary<string, object> para = new Dictionary<string, object>();
            if (context.Request.QueryString["factoryid"] != null)
            {
                para["factoryid"] = EncryptAndDecryptTool.DesDecrypt(context.Request.QueryString["factoryid"]);
            }
            DataTable dt = pdb.GetWorkcenterBarInfo(para);
            var json = JsonConvert.SerializeObject(dt);
            context.Response.ContentType = "text/json";
            context.Response.Write(json.ToString());
            context.Response.End();
        }
        //各中心任务完成情况（柱状图）--明细信息
        if (context.Request.QueryString["type"] != null && context.Request.QueryString["type"] == "GetWorkcenterBarDetailInfo")
        {
            Dictionary<string, object> para = new Dictionary<string, object>();
            if (context.Request.Form["workcentername"] != null)
            {
                para["workcentername"] = context.Request.Form["workcentername"].ToString();
            }
            if (context.Request.Form["queryType"] != null)
            {
                para["queryType"] = context.Request.Form["queryType"].ToString();
            }
            if (context.Request.Form["page"] != null)
            {
                para["page"] = context.Request.Form["page"].ToString();
            }
            if (context.Request.Form["rows"] != null)
            {
                para["rows"] = context.Request.Form["rows"].ToString();
            }

            int pageCount = 0;
            int rowCount = 0;

            DataTable dt = new DataTable();

            if (context.Request.Form["queryType"].ToString() == "已完成")
            {
                dt = pdb.GetWorkcenterFinishDetailInfo(para, out pageCount, out rowCount);
            }
            if (context.Request.Form["queryType"].ToString() == "剩余")
            {
                dt = pdb.GetWorkcenterNotFinishDetailInfo(para, out pageCount, out rowCount);
            }
            if (context.Request.Form["queryType"].ToString() == "超期")
            {
                dt = pdb.GetWorkcenterDelayDetailInfo(para, out pageCount, out rowCount);
            }

            var json = JsonConvert.SerializeObject(dt);
            context.Response.ContentType = "text/json";
            json = "{\"data\":" + json.ToString()
                    + ",\"count\":" + rowCount
                    + ",\"code\":" + "0"
                    + ",\"msg\":" + "0"
                    + "}";
            context.Response.Write(json.ToString());
            context.Response.End();
        }
        //各工区考核（超期生产任务、未达标管理任务、考核得分）
        if (context.Request.QueryString["type"] != null && context.Request.QueryString["type"] == "GetWorkcenterKaoHe")
        {
            Dictionary<string, object> para = new Dictionary<string, object>();
            if (context.Request.QueryString["factoryid"] != null)
            {
                para["factoryid"] = EncryptAndDecryptTool.DesDecrypt(context.Request.QueryString["factoryid"]);
            }
            DataTable dt = pdb.GetWorkcenterKaoHe(para);
            var json = JsonConvert.SerializeObject(dt);
            context.Response.ContentType = "text/json";
            context.Response.Write(json.ToString());
            context.Response.End();
        }
        //工区考核--超期生产任务明细
        if (context.Request.Form["type"] != null && context.Request.Form["type"] == "GetWorcenterDelayDetails")
        {
            Dictionary<string, object> para = new Dictionary<string, object>();
            if (context.Request.Form["workcentername"] != null)
            {
                para["workcentername"] = context.Request.Form["workcentername"].ToString();
            }
            if (context.Request.Form["page"] != null)
            {
                para["page"] = context.Request.Form["page"].ToString();
            }
            if (context.Request.Form["rows"] != null)
            {
                para["rows"] = context.Request.Form["rows"].ToString();
            }

            int pageCount = 0;
            int rowCount = 0;

            DataTable dt = pdb.GetWorkcenterDelayDetailInfo(para, out pageCount, out rowCount);

            var json = JsonConvert.SerializeObject(dt);
            context.Response.ContentType = "text/json";
            //json = "{\"rows\":" + json.ToString() + ",\"total\":" + rowCount + "}";
            json = "{\"data\":" + json.ToString()
                    + ",\"count\":" + rowCount
                    + ",\"code\":" + "0"
                    + ",\"msg\":" + "0"
                    + "}";
            context.Response.Write(json.ToString());
            context.Response.End();
        }
        //工区、处室--未达标管理任务明细
        if (context.Request.Form["type"] != null && context.Request.Form["type"] == "GetWorcenterWdbDetails")
        {
            Dictionary<string, object> para = new Dictionary<string, object>();
            if (context.Request.Form["workcentername"] != null)
            {
                para["workcentername"] = context.Request.Form["workcentername"].ToString();
            }
            if (context.Request.Form["page"] != null)
            {
                para["page"] = context.Request.Form["page"].ToString();
            }
            if (context.Request.Form["rows"] != null)
            {
                para["rows"] = context.Request.Form["rows"].ToString();
            }

            int pageCount = 0;
            int rowCount = 0;

            DataTable dt = pdb.GetWorkcenterWdbDetailInfo(para, out pageCount, out rowCount);

            var json = JsonConvert.SerializeObject(dt);
            context.Response.ContentType = "text/json";

            json = "{\"data\":" + json.ToString()
                    + ",\"count\":" + rowCount
                    + ",\"code\":" + "0"
                    + ",\"msg\":" + "0"
                    + "}";
            context.Response.Write(json.ToString());
            context.Response.End();
        }

        //处室考核（超期问题、未达标生产问题、考核得分）
        if (context.Request.QueryString["type"] != null && context.Request.QueryString["type"] == "GetChuShiKaoHe")
        {
            Dictionary<string, object> para = new Dictionary<string, object>();
            if (context.Request.QueryString["factoryid"] != null)
            {
                para["factoryid"] = EncryptAndDecryptTool.DesDecrypt(context.Request.QueryString["factoryid"]);
            }
            DataTable dt = pdb.GetChuShiKaoHe(para);
            var json = JsonConvert.SerializeObject(dt);
            context.Response.ContentType = "text/json";
            context.Response.Write(json.ToString());
            context.Response.End();
        }
        //各处室--超期生产问题明细
        if (context.Request.Form["type"] != null && context.Request.Form["type"] == "GetChuShiDelayProblem")
        {
            Dictionary<string, object> para = new Dictionary<string, object>();
            if (context.Request.Form["resWorkcenter"] != null)
            {
                para["resWorkcenter"] = context.Request.Form["resWorkcenter"].ToString();
            }
            if (context.Request.Form["factoryid"] != null)
            {
                para["factoryid"] = EncryptAndDecryptTool.DesDecrypt(context.Request.Form["factoryid"].ToString());
            }
            if (context.Request.Form["page"] != null)
            {
                para["page"] = context.Request.Form["page"].ToString();
            }
            if (context.Request.Form["rows"] != null)
            {
                para["rows"] = context.Request.Form["rows"].ToString();
            }

            int pageCount = 0;
            int rowCount = 0;

            DataTable dt = pdb.GetChuShiDelayProblem(para, out pageCount, out rowCount);

            var json = JsonConvert.SerializeObject(dt);
            context.Response.ContentType = "text/json";

            json = "{\"data\":" + json.ToString()
                    + ",\"count\":" + rowCount
                    + ",\"code\":" + "0"
                    + ",\"msg\":" + "0"
                    + "}";
            context.Response.Write(json.ToString());
            context.Response.End();
        }
        //生产工区得分明细
        if (context.Request.Form["type"] != null && context.Request.Form["type"] == "GetWorkcenterScoreDetails")
        {
            Dictionary<string, object> para = new Dictionary<string, object>();
            if (context.Request.Form["workcentername"] != null)
            {
                para["workcentername"] = context.Request.Form["workcentername"].ToString();
            }
            if (context.Request.Form["factoryid"] != null)
            {
                para["factoryid"] = EncryptAndDecryptTool.DesDecrypt(context.Request.Form["factoryid"].ToString());
            }

            DataTable dt = pdb.GetWorkcenterScoreDetails(para);

            var json = JsonConvert.SerializeObject(dt);
            context.Response.ContentType = "text/json";
            //json = "{\"rows\":" + json.ToString() + ",\"total\":" + 6 + "}";
            json = "{\"data\":" + json.ToString()
                    + ",\"count\":" + "6"
                    + ",\"code\":" + "0"
                    + ",\"msg\":" + "0"
                    + "}";
            context.Response.Write(json.ToString());
            context.Response.End();
        }
        //处室得分明细
        if (context.Request.Form["type"] != null && context.Request.Form["type"] == "GetChushiScoreDetails")
        {
            Dictionary<string, object> para = new Dictionary<string, object>();
            if (context.Request.Form["workcentername"] != null)
            {
                para["workcentername"] = context.Request.Form["workcentername"].ToString();
            }
            if (context.Request.Form["factoryid"] != null)
            {
                para["factoryid"] = EncryptAndDecryptTool.DesDecrypt(context.Request.Form["factoryid"].ToString());
            }

            DataTable dt = pdb.GetChushiScoreDetails(para);

            var json = JsonConvert.SerializeObject(dt);
            context.Response.ContentType = "text/json";

            json = "{\"data\":" + json.ToString()
                    + ",\"count\":" + "6"
                    + ",\"code\":" + "0"
                    + ",\"msg\":" + "0"
                    + "}";
            context.Response.Write(json.ToString());
            context.Response.End();
        }
    }
}